package coder.user.controller;

import coder.common.Result;
import coder.user.entity.Approve;
import coder.user.service.IApproveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("approve")
@Slf4j
public class ApproveController {

    @Autowired
    private IApproveService approveService;


    /**
     * 提交审批请求
     *
     * 该方法处理审批提交请求，接收审批信息并调用服务层方法进行处理
     * 使用@PostMapping注解限定HTTP POST请求，路径为"/submit"
     *
     * @param approve 审批对象，通过@ModelAttribute注解绑定前端表单数据
     * @return 返回一个Result<String>对象，包含处理结果信息
     */
    @PostMapping("submit")
    public Result<String> submitApprove(@ModelAttribute Approve approve) {
        // 调用业务逻辑方法提交审批
        approveService.submitApprove(approve);
        // 返回成功结果
        return Result.success("提交成功");
    }

    @PostMapping("update")
    public Result<String> updateApprove(@ModelAttribute Approve approve) {
         approveService.updateApprove(approve);
        // 返回成功结果
        return Result.success("提交成功");
    }
}
